#include "StdAfx.h"
#include "Scene.h"

	//==========================================================================================
	//																			what from project file
	//==========================================================================================
Scene::Scene(String^ path_p)
{
	path_=path_p;
	outerName="null";
	numOfFiles=0;
	
	a=false;
	//b=false;
	c=false;
	d=false;
	e=false;
	Duration=5;
	//e=true;
	description="undefined";
	
	majorNumber=-1;
	//c=true;
	if(valid())
	{CreateScene();}
}
bool 
Scene::SetInnerName(String^ inner)
{
	bool result=false;
	if(innerName=inner)
	{
		result=true;
		a=true;
			if(valid())
	{CreateScene();}
	}
	return result;
}
bool 
Scene::SetOuterName(String^ outer)
{
	bool result=false;
	if(outerName=outer)
	{
		result=true;
		b=true;
			if(valid())
	{CreateScene();}
	}
	return result;
}
String^ 
Scene::GetInnerName(void)
{
	return innerName;
}
String^ 
Scene::GetOuterName(void)
{
	return outerName;
}
void 
Scene::SetMajorNumber(int num)
{
	majorNumber=num;
	c=true;
		if(valid())
	{CreateScene();}
}
void 
Scene::SetDescription(String^ str)
{
	description=str;
	d=true;
		if(valid())
	{CreateScene();}
}
String^ 
Scene::GetDescription(void)
{
	return description;
}
void 
Scene::SetDuration(int dur)
{
	Duration=dur;
	e=true;
		if(valid())
	{CreateScene();}
}
int 
Scene::GetDuration(void)
{
	return Duration;
}
bool 
Scene::valid(void)
{
	if(a && b && c && d && e)
	{return true;}
	return false;
}


String^ 
Scene::GetPicName(void)
{
	String^ picName;
	picName=Path::Combine(path_, outerName);
	picName=Path::Combine(picName, "render_1.png");
	if(File::Exists(picName))return picName;
	else return "null";
}
int 
Scene::GetMajorNumber(void)
{
	return majorNumber;
}

bool 
Scene::RenameOuterName(String^ outer)
{
	bool result=false;
	if(Directory::Exists(System::IO::Path::Combine(path_, outerName)))
	{
		if(outerName==outer){}
		else
		{
			try
			{
				Directory::Move(System::IO::Path::Combine(path_, outerName),System::IO::Path::Combine(path_, outer));result=true;
			}
			catch(String^ exx)
			{}
		}
			
	}
	outerName=outer;
	return result;
}
	//==========================================================================================
	//																			how the scene creates
	//==========================================================================================
void 
Scene::CreateScene(void)
{
	if(Directory::Exists(System::IO::Path::Combine(path_, outerName))){}
	else
	{
		if(Directory::CreateDirectory(System::IO::Path::Combine(path_, outerName)))
		{
			int i=1;
			while(i<4)
			{
				if(!CreateSF(i,System::IO::Path::Combine(path_, outerName))){break;}
				i++;
			}
		}
	}
}
bool
Scene::CreateSF(int TYPE, String^ whereIt)
{
	bool result=false;
	if(numOfFiles==0){Files=gcnew array<SynfigFile^>(3);}
	if(numOfFiles>2){numOfFiles=0;}
	if(TYPE==BACKGROUND)//Files[0]=gcnew SynfigFile();
	{
		if(Files[numOfFiles]=gcnew SynfigFile(TYPE, whereIt, Duration))
		{
			numOfFiles++;
			result=true;
		}
	}
	if(TYPE==FIGURES)//Files[0]=gcnew SynfigFile();
	{
		if(Files[numOfFiles]=gcnew SynfigFile(TYPE, whereIt, Duration))
		{
			numOfFiles++;
			result=true;
		}
	}
	if(TYPE==RENDER)//Files[0]=gcnew SynfigFile();
	{
		if(Files[numOfFiles]=gcnew SynfigFile(TYPE, whereIt, Duration))
		{
			numOfFiles++;
			result=true;
		}
	}
	//else if(TYPE==FIGURES)
	//{}
	return result;
}


bool 
Scene::isReady(void)
{
	return valid();
}
